import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/models/xindong_withdraw_class.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/routes/user/wallet/xindong_wallet_ctr.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/container/xindong_empty_container.dart';

class XinDongWithDrawYeMian extends StatelessWidget {
  const XinDongWithDrawYeMian({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar("提现"),
      body: GetBuilder<XinDongUserController>(builder: (userController) {
        return GetBuilder<XinDongWalletCtr>(
          initState: (state) {
            XinDongWalletCtr.to.requestWithdrawList();
          },
          builder: (controller) {
            return CustomScrollView(
              physics: const AlwaysScrollableScrollPhysics(),
              slivers: <Widget>[
                SliverToBoxAdapter(
                  child: Container(
                    height: kCellHeight,
                    color: DZColors.cellColor,
                    padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
                    margin: const EdgeInsets.only(bottom: 1),
                    child: Row(
                      children: [
                        const Text(
                          "积分余额：",
                          style: TextStyle(color: DZColors.titleColor, fontSize: 16, height: 1.2),
                        ),
                        Text(
                          "${controller.score}",
                          style: const TextStyle(color: DZColors.moneyColor, fontSize: 15, height: 1.2),
                        ),
                      ],
                    ),
                  ),
                ),
                SliverToBoxAdapter(
                  child: Container(
                    height: kCellHeight,
                    color: DZColors.cellColor,
                    padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
                    margin: const EdgeInsets.only(bottom: 1),
                    child: Row(
                      children: [
                        const Text(
                          "冻结积分：",
                          style: TextStyle(color: DZColors.titleColor, fontSize: 16, height: 1.2),
                        ),
                        Text(
                          "${controller.dongJieScore}",
                          style: const TextStyle(color: DZColors.moneyColor, fontSize: 15, height: 1.2),
                        ),
                      ],
                    ),
                  ),
                ),
                SliverToBoxAdapter(
                  child: Container(
                    height: kCellHeight,
                    color: DZColors.cellColor,
                    padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
                    margin: const EdgeInsets.only(bottom: 1),
                    child: Row(
                      children: [
                        const Text(
                          "可提现积分：",
                          style: TextStyle(color: DZColors.titleColor, fontSize: 16, height: 1.2),
                        ),
                        Text(
                          "${controller.withdrawScore}",
                          style: const TextStyle(color: DZColors.moneyColor, fontSize: 15, height: 1.2),
                        ),
                      ],
                    ),
                  ),
                ),

                // 评论
                SliverToBoxAdapter(
                  child: Container(
                    color: DZColors.backgroundColor,
                    padding: const EdgeInsets.only(left: kPaddingValue, top: 10, bottom: 10),
                    child: const Text(
                      "提现面额",
                      style: TextStyle(fontSize: 15, color: DZColors.titleColor, fontWeight: FontWeight.w600),
                    ),
                  ),
                ),

                // 列表
                XinDongEmptyContainer(
                  dataList: controller.withdrawList,
                  containSliver: true,
                  child: SliverPadding(
                    padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
                    sliver: SliverGrid.builder(
                      itemCount: controller.withdrawList?.length ?? 0,
                      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 2, // 一行的Widget数量
                        crossAxisSpacing: 8, //水平间距
                        mainAxisSpacing: 8, //垂直间距
                        childAspectRatio: 1, //子Widget宽高比例
                      ),
                      itemBuilder: (BuildContext context, int index) {
                        XinDongWithdrawClass model = controller.withdrawList![index];
                        return GestureDetector(
                          onTap: () => controller.requestTiXian(model: model),
                          behavior: HitTestBehavior.opaque,
                          child: Container(
                            clipBehavior: Clip.antiAlias,
                            decoration: BoxDecoration(borderRadius: BorderRadius.circular(10)),
                            child: Stack(
                              alignment: Alignment.center,
                              children: [
                                ImageUtil.asset(AssetsRes.WITHDRAW_MONEY_BG),
                                Text(model.title, style: const TextStyle(fontSize: 30, color: Colors.white)),
                                Positioned(
                                  bottom: 10,
                                  child: Text(
                                    "消耗${model.price}积分",
                                    style: const TextStyle(fontSize: 16, color: DZColors.moneyColor),
                                  ),
                                )
                              ],
                            ),
                          ),
                        );
                      },
                    ),
                  ),
                ),
              ],
            );
          },
        );
      }),
    );
  }
}
